package com.neu.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.neu.mapper.InventoryMapper;
import com.neu.mapper.SalesreturnMapper;
import com.neu.po.Salesreturn;
import com.neu.po.SalesreturnExample;
import com.neu.view.BigType2;
@Service
public class SalesreturnServiceImpl implements SalesreturnService {
	
	@Autowired
	private SalesreturnMapper salesreturnMapper;
	
	@Autowired
	private InventoryMapper inventoryMapper;
	
	@Override
	public PageInfo<Salesreturn> getPaged(int pageNum, int pageSize, String keyword) {
		SalesreturnExample example = new SalesreturnExample();
		
		PageHelper.startPage(pageNum, pageSize);
		
		List<Salesreturn> list = salesreturnMapper.selectByExample(example);
		
		PageInfo<Salesreturn> pageinfo = new PageInfo<>(list);
		
		return pageinfo;
	}

	@Override
	@Transactional
	public int insertUpdate(BigType2 bigType2) {
		int a = salesreturnMapper.insert(bigType2.getSalesreturn());
		int b = inventoryMapper.updateByPrimaryKey(bigType2.getInventory());
		
		if(a == 1 && b == 1) {
			return 1;
		}
		
		return 0;
	}

}
